package com.xxg.renrenorder.dao;

import com.xxg.renrencommon.domain.dao.BaseMapper;
import com.xxg.renrencommon.domain.dao.RenrenShopGoodsOption;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * RenrenShopGoodsOptionDao继承基类
 */
@Mapper
@Repository
public interface RenrenShopGoodsOptionDao extends BaseMapper<RenrenShopGoodsOption, Integer> {
    /**
     * 在指定范围内查询数据
     *
     * @param ids ID列表
     * @return 结果
     */
    @Select({"<script>",
            "select id,shop_id as shopId,goods_id as goodsId,title,thumb,price,cost_price as costPrice,",
            "original_price as originalPrice,stock,sales from renren_shop_goods_option where goods_id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    List<RenrenShopGoodsOption> selectByGoodsIds(@Param("ids") List<Integer> ids);

    @Update("update renren_shop_goods_option set stock=#{stock,jdbcType=INTEGER}, sales=#{sales,jdbcType=INTEGER} where id=#{id,jdbcType=INTEGER}")
    void updateStockById(@Param("stock") Integer newStock, @Param("sales") Integer sales, @Param("id") Integer id);

    @Update({"<script>",
            "update renren_shop_goods_option set stock=#{stock,jdbcType=INTEGER}, sales=#{sales,jdbcType=INTEGER}",
            "where id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    void updateStockByIds(@Param("ids") List<Integer> ids, @Param("stock") Integer stock, @Param("sales") Integer sales);
}